/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.daoImpl;

import br.com.deployment.dao.CityDAO;
import br.com.deployment.entities.City;
import br.com.deployment.genericdao.GenericDAO;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author ely
 */
@Stateless
@LocalBean
public class CityDAOImpl extends GenericDAO<City> implements CityDAO{

    public CityDAOImpl(){
        super(City.class);
    }
    
    @Override
    public List<City> findCity(City city) {
       List<City> lista = new ArrayList<City>();
       String sql = "Select c from City c where lower(c.name) like lower(:name)";
       Query query = getEntityManager().createQuery(sql);
       
        if (city.getName() !=  null) {
                query.setParameter("name", "%"+city.getName()+"%");
        }
        
       lista = query.getResultList();
       return lista;
    }
    
}
